package cn.wyu.web;

import cn.wyu.pojo.Article;
import cn.wyu.service.ArticleService;
import cn.wyu.service.ArticleServletImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/articleInfo.do")
public class ArticleServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //处理中文乱码
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //获得浏览器发过来的数据
        String articleID = request.getParameter("articleID");

        //交给业务层查询
        ArticleService al = new ArticleServletImpl();
        Article article = (Article) al.findByArticleID(articleID);

        //将得到的对象，放到request域中
        request.setAttribute("article",article);

        //转发到详情页面
        request.getRequestDispatcher("WEB-INF/articleInfo.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
